package com.aaa.controller.mht;

import com.aaa.controller.BaseController;
import com.aaa.entity.PageSortEntity;
import com.aaa.entity.Result;
import com.aaa.entity.mht.QuestionMht;
import com.aaa.service.mht.QuestionMhtService;
import com.github.pagehelper.Page;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.Date;
import java.util.List;

/**
 * 心理健康诊断测验(QuestionMht)表控制层
 *
 * @author makejava
 * @since 2022-08-31 15:45:50
 */
@RestController
@RequestMapping("questionMht")
public class QuestionMhtController extends BaseController {
    /**
     * 服务对象
     */
    @Resource
    private QuestionMhtService questionMhtService;

    /**
     * 分页查询
     *
     * @param :pageSortEntity 筛选条件
     * @return Result
     * @param: questionMht      分页对象
     */

    @RequestMapping(value = "queryAllByCondition.do", method = RequestMethod.GET)
    public Result queryAllByCondition(PageSortEntity pageSortEntity, QuestionMht questionMht) {
        List<QuestionMht> questionMhtList = questionMhtService.queryAllByCondition(pageSortEntity, questionMht);
        Page page = (Page) questionMhtList;

        return success(page.getResult(), page.getTotal());
    }

    @RequestMapping(value = "addQuestionMht.do")
    public Result saveQuestionMht(QuestionMht questionMht) {
        questionMht.setCreateBy("liuyichen");
        questionMht.setCreateTime(new Date());
        int insert = questionMhtService.save(questionMht);
        if (insert > 0) {
            return success();
        } else {
            return fail();
        }
    }

    @RequestMapping(value = "delQuestionMht.do")
    public Result delQuestionMhtById(Integer id) {
        boolean b = questionMhtService.deleteById(id);
        if (b) {
            return success();
        } else {
            return fail();
        }
    }

    @RequestMapping(value = "delQuestionMhtBatch.do")
    public Result delQuestionMhtBatch(int[] id) {
        int i = questionMhtService.delQuestionMhtBatch(id);
        if (i > 0) {
            return success();
        } else {
            return fail();
        }
    }

    @RequestMapping(value = "updateQuestionMht.do")
    public Result updateQuestionMht(QuestionMht questionMht) {
        int update = questionMhtService.update(questionMht);
        if (update > 0) {
            return success();
        } else {
            return fail();
        }
    }

    @GetMapping(value = "repetitionName.do")
    public Result repetitionName(QuestionMht questionMht) {
        int i = questionMhtService.repetitionName(questionMht);
        if (i > 0) {
            return fail("题目已存在");
        } else {
            return success("题目可使用");
        }
    }


}

